<!DOCTYPE html>
<html prefix="
og: http://ogp.me/ns#
article: http://ogp.me/ns/article#
" lang="zh_cn">
<head>
<meta charset="utf-8">
<meta name="description" content="python, go, ML, bigdata">
<meta name="viewport" content="width=device-width">
<title>vincent blog | vincent blog</title>
<link href="assets/css/all-nocdn.css" rel="stylesheet" type="text/css">
<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.xml">
<link rel="canonical" href="https://wisonwang.github.io/">
<!--[if lt IE 9]><script src="/assets/js/html5.js"></script><![endif]--><style>
    div.input_prompt {
      display: none;
    }
    </style>
</head>
<body>
    <section class="social"><ul>
<li><a href="#" title="Home"><i class="icon-home"></i></a></li>
            <li><a href="archive.html" title="文章存档"><i class="icon-archive"></i></a></li>
            <li><a href="categories/" title="标签"><i class="icon-tags"></i></a></li>
            <li><a href="pages/about" title="About"><i class="icon-about"></i></a></li>
            <li><a href="rss.xml" title="RSS 源"><i class="icon-rss"></i></a></li>
            <li><a href="https://twitter.com/wisonwang" title="My Twitter"><i class="icon-twitter"></i></a></li>
            <li><a href="https://github.com/wisonwang" title="My Github"><i class="icon-github"></i></a></li>

        </ul></section><section class="page-content"><div class="content" rel="main">
        <div class="post">
            <h1 class="title"><a href="posts/python-grpc-shi-yong/">python grpc 使用</a></h1>
            <div class="meta">
                <div class="authordate">
                    <time class="timeago" datetime="2019-10-11T09:48:21+08:00">2019-10-11 09:48</time>
</div>
                <div class="stats">
                                <a href="posts/python-grpc-shi-yong/#disqus_thread" data-disqus-identifier="cache/posts/python-grpc-shi-yong.html">Comments</a>


                </div>
            
            </div>
            <div class="body">
                <div>
<p>
grpc 是google开发的远程通信协议,和它最相近的产品的产品是apache基金会下的thrift协议。
两者都是很优秀的通信中间件产品，拥有很好的性能，支持大多数主要语言。
相对于thrift协议，更年轻，更轻量，grpc基于http2传输协议和protocol buffer(也可以使用json)序列化协议。
</p>

<p>
这也带来相对于thrfit的优点：
</p>

<ol class="org-ol">
<li>http2相对于thrfit的tcp协议更容易扩展，参见<sup><a id="fnr.1" class="footref" href="posts/python-grpc-shi-yong/#fn.1">1</a></sup>:

<ul class="org-ul">
<li>相对于http1.x,http2采用二进制传输，同时多次请求时会对http协议的header信息进行压缩，从而大幅提高http2的性能</li>

<li>多路复用/请求流控制，相对于http1是同步请求，一个链接同一时间只能处理一个请求。http2是完全异步请求，
在同一个tcp链接上客户端和服务端可以同时进行多次请求响应。</li>

<li>基于多路复用和请求流控制，通过新增了一个带stream参数的流化或者类似于管道通信功能，这一点和通常的rpc协议差别很大，
不管在服务端实现上还是客户端调用上都和常规的rpc请求不同，后面的例子中可以具体看到这种差异.</li>

<li>易于扩展，例如：在异构系统（例如微服务系统）中，一次真是的客户端请求发生了，实际在发生很多次的服务间调用，
使用http协议可以方便的扩展，增加调用堆栈/流信息，方便日志记录。</li>
</ul>
</li>

<li>protocol buffer 本身是一个独立的高性能序列化协议，在程序内部能够有很好的通用性，可以直接作为内部数据的表示方式，也可以直接
用于缓存数据。</li>
</ol>
<p class="more"><a href="posts/python-grpc-shi-yong/">更多…</a></p>
</div>
            </div>
        </div>
        <div class="post">
            <h1 class="title"><a href="posts/zi-jian-httpszhan-dian/">自建https站点</a></h1>
            <div class="meta">
                <div class="authordate">
                    <time class="timeago" datetime="2019-10-09T15:05:23+08:00">2019-10-09 15:05</time>
</div>
                <div class="stats">
                                <a href="posts/zi-jian-httpszhan-dian/#disqus_thread" data-disqus-identifier="cache/posts/zi-jian-httpszhan-dian.html">Comments</a>


                </div>
            
            </div>
            <div class="body">
                <div>
<p>
现在https已经成为web服务的标配了，由于完整的https部署流程需要一系列的备案申请ca的一些过程，
不适合开发人员调试https服务功能，这样创建自授权的https就很有用了。
</p>

<p>
（注：自授权的证书不会被浏览器识别为可信的证书，可以在系统中添加该ca证书为可信证书即可）
</p>

<p>
如下介绍创建自授权的https站点流程，以nginx配置为例：
</p>

<p class="more"><a href="posts/zi-jian-httpszhan-dian/">更多…</a></p>
</div>
            </div>
        </div>
        <div class="post">
            <h1 class="title"><a href="posts/python-meta-class/">python meta class</a></h1>
            <div class="meta">
                <div class="authordate">
                    <time class="timeago" datetime="2019-04-15T18:10:46+08:00">2019-04-15 18:10</time>
</div>
                <div class="stats">
                                <a href="posts/python-meta-class/#disqus_thread" data-disqus-identifier="cache/posts/python-meta-class.html">Comments</a>


                </div>
            
            </div>
            <div class="body">
                <div tabindex="-1" id="notebook" class="border-box-sizing">
    <div class="container" id="notebook-container">

<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>python的元类(metaclass)和虚基类（ABC）</p>
<p>== metaclass  ==</p>
<p>== ABC虚基类 ==</p>
<p class="more"><a href="posts/python-meta-class/">更多…</a></p>
</div>
</div>
</div>
</div>
</div>
            </div>
        </div>
        <div class="post">
            <h1 class="title"><a href="posts/python-function-tools/">python function tools</a></h1>
            <div class="meta">
                <div class="authordate">
                    <time class="timeago" datetime="2019-04-02T16:55:28+08:00">2019-04-02 16:55</time>
</div>
                <div class="stats">
                                <a href="posts/python-function-tools/#disqus_thread" data-disqus-identifier="cache/posts/python-function-tools.html">Comments</a>


                </div>
            
            </div>
            <div class="body">
                <div tabindex="-1" id="notebook" class="border-box-sizing">
    <div class="container" id="notebook-container">

<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p class="more"><a href="posts/python-function-tools/">更多…</a></p>
</div>
</div>
</div>
</div>
</div>
            </div>
        </div>
        <div class="post">
            <h1 class="title"><a href="posts/django-authoauth20/">django auth&amp;oauth2.0</a></h1>
            <div class="meta">
                <div class="authordate">
                    <time class="timeago" datetime="2019-03-28T17:09:24+08:00">2019-03-28 17:09</time>
</div>
                <div class="stats">
                                <a href="posts/django-authoauth20/#disqus_thread" data-disqus-identifier="cache/posts/django-authoauth20.html">Comments</a>


                </div>
            
            </div>
            <div class="body">
                <div tabindex="-1" id="notebook" class="border-box-sizing">
    <div class="container" id="notebook-container">

<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">requests</span>
<span class="kn">import</span> <span class="nn">urllib</span>
</pre></div>

    </div>
</div>
</div>

</div>
    </div>
  </div>

            </div>
        </div>
        <div class="post">
            <h1 class="title"><a href="posts/sklearn-word2vecsuan-fa/">sklearn word2vec算法</a></h1>
            <div class="meta">
                <div class="authordate">
                    <time class="timeago" datetime="2019-01-21T11:06:35+08:00">2019-01-21 11:06</time>
</div>
                <div class="stats">
                                <a href="posts/sklearn-word2vecsuan-fa/#disqus_thread" data-disqus-identifier="cache/posts/sklearn-word2vecsuan-fa.html">Comments</a>


                </div>
            
            </div>
            <div class="body">
                <div tabindex="-1" id="notebook" class="border-box-sizing">
    <div class="container" id="notebook-container">

<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [1]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">sklearn</span>

<span class="kn">import</span> <span class="nn">sys</span>

<span class="n">sys</span><span class="o">.</span><span class="n">path</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

    <div class="prompt output_prompt">Out[1]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>['',
 '/anaconda3/envs/py36spark21/lib/python36.zip',
 '/anaconda3/envs/py36spark21/lib/python3.6',
 '/anaconda3/envs/py36spark21/lib/python3.6/lib-dynload',
 '/anaconda3/envs/py36spark21/lib/python3.6/site-packages',
 '/anaconda3/envs/py36spark21/lib/python3.6/site-packages/IPython/extensions',
 '/Users/vincent/.ipython']</pre>
</div>

</div>

</div>
</div>

</div>
    </div>
  </div>

            </div>
        </div>
        <div class="post">
            <h1 class="title"><a href="posts/scipy_example/">scipy_example</a></h1>
            <div class="meta">
                <div class="authordate">
                    <time class="timeago" datetime="2019-01-18T10:26:50+08:00">2019-01-18 10:26</time>
</div>
                <div class="stats">
                                <a href="posts/scipy_example/#disqus_thread" data-disqus-identifier="cache/posts/scipy_example.html">Comments</a>


                </div>
            
            </div>
            <div class="body">
                <div tabindex="-1" id="notebook" class="border-box-sizing">
    <div class="container" id="notebook-container">

<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [2]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">scipy</span>
</pre></div>

    </div>
</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [4]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(([</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="mi">5</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mf">1.002</span><span class="p">,</span> <span class="mi">2</span><span class="o">/</span><span class="mf">9.0</span><span class="p">)))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"a = "</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span>

<span class="nb">print</span><span class="p">(</span><span class="s2">"np.r_[3,[0]*5,-1:1:10j] = "</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">r_</span><span class="p">[</span><span class="mi">3</span><span class="p">,[</span><span class="mi">0</span><span class="p">]</span><span class="o">*</span><span class="mi">5</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="mi">1</span><span class="p">:</span><span class="mi">10</span><span class="n">j</span><span class="p">])</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

    <div class="prompt"></div>


<div class="output_subarea output_stream output_stdout output_text">
<pre>a =  [ 3.          0.          0.          0.          0.          0.
 -1.         -0.77777778 -0.55555556 -0.33333333 -0.11111111  0.11111111
  0.33333333  0.55555556  0.77777778  1.        ]
np.r_[3,[0]*5,-1:1:10j] =  [ 3.          0.          0.          0.          0.          0.
 -1.         -0.77777778 -0.55555556 -0.33333333 -0.11111111  0.11111111
  0.33333333  0.55555556  0.77777778  1.        ]
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [5]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="s2">"np.mgrid[0:5:4j,0:5:4j] = "</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">mgrid</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">5</span><span class="p">:</span><span class="mi">4</span><span class="n">j</span><span class="p">,</span><span class="mi">0</span><span class="p">:</span><span class="mi">5</span><span class="p">:</span><span class="mi">4</span><span class="n">j</span><span class="p">])</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

    <div class="prompt"></div>


<div class="output_subarea output_stream output_stdout output_text">
<pre>np.mgrid[0:5:4j,0:5:4j] =  [[[0.         0.         0.         0.        ]
  [1.66666667 1.66666667 1.66666667 1.66666667]
  [3.33333333 3.33333333 3.33333333 3.33333333]
  [5.         5.         5.         5.        ]]

 [[0.         1.66666667 3.33333333 5.        ]
  [0.         1.66666667 3.33333333 5.        ]
  [0.         1.66666667 3.33333333 5.        ]
  [0.         1.66666667 3.33333333 5.        ]]]
</pre>
</div>
</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [10]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">poly1d</span><span class="p">([</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"p = "</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"p*p="</span><span class="p">,</span> <span class="n">p</span><span class="o">*</span><span class="n">p</span><span class="p">)</span>

<span class="nb">print</span><span class="p">(</span><span class="s1">'p.integ(k=6) = '</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">integ</span><span class="p">(</span><span class="n">k</span><span class="o">=</span><span class="mi">6</span><span class="p">))</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

    <div class="prompt"></div>


<div class="output_subarea output_stream output_stdout output_text">
<pre>p =     2
3 x + 4 x + 5
p*p=    4      3      2
9 x + 24 x + 46 x + 40 x + 25
p.integ(k=6) =     3     2
1 x + 2 x + 5 x + 6
</pre>
</div>
</div>

</div>
</div>

</div>
    </div>
  </div>

            </div>
        </div>
        <div class="post">
            <h1 class="title"><a href="posts/orgblog/">org blog</a></h1>
            <div class="meta">
                <div class="authordate">
                    <time class="timeago" datetime="2019-01-15T22:39:22+08:00">2019-01-15 22:39</time>
</div>
                <div class="stats">
                                <a href="posts/orgblog/#disqus_thread" data-disqus-identifier="cache/posts/orgblog.html">Comments</a>


                </div>
            
            </div>
            <div class="body">
                <p>
在这里书写你的文章。
</p>
            </div>
        </div>
        <div class="post">
            <h1 class="title"><a href="posts/ipython%2Bmatplotlib%E6%95%B0%E6%8D%AE%E5%B1%95%E7%A4%BA/">ipython+matplotlib数据展示</a></h1>
            <div class="meta">
                <div class="authordate">
                    <time class="timeago" datetime="2019-01-15T21:54:29+08:00">2019-01-15 21:54</time>
</div>
                <div class="stats">
                                <a href="posts/ipython%2Bmatplotlib%E6%95%B0%E6%8D%AE%E5%B1%95%E7%A4%BA/#disqus_thread" data-disqus-identifier="cache/posts/python_matplotlib.html">Comments</a>


                </div>
            
            </div>
            <div class="body">
                <div tabindex="-1" id="notebook" class="border-box-sizing">
    <div class="container" id="notebook-container">

<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>使用ipython + matplotlib 绘制图形。</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [1]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="c1">#import matplotlib</span>
<span class="c1">#matplotlib.use('Agg')</span>

<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>


<span class="c1">#First create some toy data:</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="p">,</span> <span class="mi">400</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>

<span class="c1">#Creates just a figure and only one subplot</span>
<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">()</span>
<span class="n">ax</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'Simple plot'</span><span class="p">)</span>

<span class="c1">#Creates two subplots and unpacks the output array immediately</span>
<span class="n">f</span><span class="p">,</span> <span class="p">(</span><span class="n">ax1</span><span class="p">,</span> <span class="n">ax2</span><span class="p">)</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">sharey</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">ax1</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="n">ax1</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'Sharing Y axis'</span><span class="p">)</span>
<span class="n">ax2</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>

<span class="c1">#Creates four polar axes, and accesses them through the returned array</span>
<span class="n">fig</span><span class="p">,</span> <span class="n">axes</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">subplot_kw</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span><span class="n">polar</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="n">axes</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="n">axes</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
 
<span class="c1">#Share a X axis with each column of subplots</span>
<span class="c1"># plt.subplots(2, 2, sharex='col')</span>

<span class="c1">#Share a Y axis with each row of subplots</span>
<span class="c1"># plt.subplots(2, 2, sharey='row')</span>
 
<span class="c1">#Share both X and Y axes with all subplots</span>
<span class="c1"># plt.subplots(2, 2, sharex='all', sharey='all')</span>

<span class="c1">#Note that this is the same as</span>
<span class="c1"># plt.subplots(2, 2, sharex=True, sharey=True)</span>

<span class="c1">#Creates figure number 10 with a single subplot</span>
<span class="c1">#and clears it if it already exists.</span>
<span class="c1"># fig, ax=plt.subplots(num=10, clear=True)</span>

<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

    <div class="prompt"></div>




<div class="output_text output_subarea ">
<pre>&lt;Figure size 640x480 with 1 Axes&gt;</pre>
</div>

</div>

<div class="output_area">

    <div class="prompt"></div>




<div class="output_text output_subarea ">
<pre>&lt;Figure size 640x480 with 2 Axes&gt;</pre>
</div>

</div>

<div class="output_area">

    <div class="prompt"></div>




<div class="output_text output_subarea ">
<pre>&lt;Figure size 640x480 with 4 Axes&gt;</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [4]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>


<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>


<span class="c1">#First create some toy data:</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">log2</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="mi">10</span><span class="p">)</span>

<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s1">'-'</span><span class="p">)</span>

<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

    <div class="prompt"></div>




<div class="output_png output_subarea ">
<img src="">
</div>

</div>

</div>
</div>

</div>
    </div>
  </div>

            </div>
        </div>
        <div class="post">
            <h1 class="title"><a href="posts/pythonlei-ji-zhi/">python类机制</a></h1>
            <div class="meta">
                <div class="authordate">
                    <time class="timeago" datetime="2019-01-14T13:46:23+08:00">2019-01-14 13:46</time>
</div>
                <div class="stats">
                                <a href="posts/pythonlei-ji-zhi/#disqus_thread" data-disqus-identifier="cache/posts/pythonlei-ji-zhi.html">Comments</a>


                </div>
            
            </div>
            <div class="body">
                <div tabindex="-1" id="notebook" class="border-box-sizing">
    <div class="container" id="notebook-container">

<div class="cell border-box-sizing text_cell rendered">
<div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>python 类机制</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [10]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">class</span> <span class="nc">A</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="s2">"A"</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">"A Class init: "</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">print_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">"object name: "</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">B</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="s2">"B"</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">"B Class init: "</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>


<span class="k">class</span> <span class="nc">C</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">B</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="s2">"C"</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">"C Class init:"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">print_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="nb">print</span><span class="p">(</span><span class="s2">"C object name: "</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [11]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">c</span> <span class="o">=</span> <span class="n">C</span><span class="p">()</span>

<span class="n">c</span><span class="o">.</span><span class="n">print_name</span><span class="p">()</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

    <div class="prompt"></div>


<div class="output_subarea output_stream output_stdout output_text">
<pre>C Class init: C
A Class init:  C
C object name:  C
</pre>
</div>
</div>

</div>
</div>

</div>
    </div>
  </div>

            </div>
        </div>
            <nav class="postindexpager"><ul class="pager">
<li class="next">
                <a href="index-2.html" rel="next">旧一篇</a>
            </li>
        </ul></nav><script>var disqus_shortname="wisonwanghomepage";(function(){var a=document.createElement("script");a.async=true;a.src="https://"+disqus_shortname+".disqus.com/count.js";(document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0]).appendChild(a)}());</script><footer id="footer"><p>Contents © 2020         <a href="mailto:fangfu2012@gmail.com">vincent wang</a> - Powered by         <a href="https://getnikola.com" rel="nofollow">Nikola</a>         </p>
            
        </footer>
</div>
    </section><script src="assets/js/all-nocdn.js" type="text/javascript"></script><script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script><script type="text/x-mathjax-config">
    MathJax.Hub.Config({tex2jax: {inlineMath: [['$latex ','$'], ['\\(','\\)']]}});
    </script><script type="text/javascript">
            $(function(){
                $('.timeago').timeago();
            });
        </script>
</body>
</html>
